﻿using System;
using Common;

namespace ImageProcessing.Common
{
    public class InterestPoint
    {
        public float[] Descriptor
        {
            get { return _pointInfo.Descriptor; }
            set { _pointInfo.Descriptor = value; }
        }
        public int DescriptorLength { get { return _pointInfo.DescriptorLength; } }
        public int Sign
        {
            get { return _pointInfo.Sign; }
            set { _pointInfo.Sign = value; }
        }
        public bool Matched;
        public bool Processed;
        public float Orientation;
        public float Response;
        public float Scale;

        private readonly PointInfo _pointInfo;
        public PointInfo PointInfo { get { return _pointInfo; } }

        // ugly tech debt below
        private int _xint;
        private float _xfloat;
        public float x
        {
            get { return _xfloat; }
            set { _xfloat = value; _xint = (int)value; }
        }
        public int X { get { return _xint; } }


        private int _yint;
        private float _yfloat;
        public float y
        {
            get { return _yfloat; }
            set { _yfloat = value; _yint = (int)value; }
        }
        public int Y { get { return _yint; } }

        public InterestPoint(PointInfo pointInfo)
        {
            _pointInfo = pointInfo;
            Orientation = 0;
        }

        public void SetDescriptorLength(int size)
        {
            _pointInfo.SetDescriptorLength(size);
        }

        public bool IsValidDescriptor
        {
            get
            {
                var valid = false;
                for (int i = 0; i < DescriptorLength - 1; i++)
                {
                    if (Math.Abs(Descriptor[i] - 0) > float.Epsilon)
                    {
                        valid = true;
                        break;
                    }
                }

                return valid;
            }
        }

        public TagInfo TagInfo { get { return PointInfo.TagInfo; } }
        public void SetTagInfo(TagInfo tagInfo)
        {
            PointInfo.TagInfo = tagInfo;
        }
    }
}
